<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/17
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>学员信息管理</title>
    <style>
      table tr:nth-child(odd){
        background: lightgray;
      }
    </style>
  </head>
  <body>
  <h1 align="center">学员信息列表</h1>
  <table align="center">
    <tr align="center" style="background: darkgray">
      <th>学员编号</th>
      <th>学员姓名</th>
      <th>学员性别</th>
      <th>学员年龄</th>
      <th>家庭住址</th>
      <th>Email</th>
      <th>操作</th>
    </tr>
    <c:forEach var="student" items="${sessionScope.list}">
      <tr align="center">
        <td>${student.sid}</td>
        <td><a href="StudentPersonalServlet?sid=${student.sid}">${student.sname}</a></td>
        <td>${student.sgender}</td>
        <td>${student.sage}</td>
        <td>${student.saddress}</td>
        <td>${student.semail}</td>
        <td><a href="javascript:void(0)" onclick="remove('${student.sid}')">删除</a></td>
      </tr>
    </c:forEach>
  </table>
  <div align="center"><span id="span"></span></div>
  </body>
  <script src="jq/jquery.js"></script>
  <script>

    function remove(sid) {
      if(confirm("确认要删除该学员信息？")) {
        $.getJSON(
                "StudentDeleteServlet",
                {sid: sid},
                function (data) {
                  if (data) {
                    alert("删除成功");
                    location.href = "StudentListServlet"
                  } else {
                    alert("删除失败")
                  }
                }
        )
      }
    }

    if(${sessionScope.update==1}){
      $('#span').text("更新成功");
    }else if(${sessionScope.update==0}){
      $('#span').text("更新失败");
    }else{
      $('#span').text("");
    }
  </script>
</html>
